// https://www.acwing.com/problem/content/910/

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

struct Compare {
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) const {
        return p1.second < p2.second;
    }
};

int main() {
    int n;
    scanf("%d", &n);
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &arr[i].first, &arr[i].second);
    }

    sort(arr.begin(), arr.end(), Compare());

    long end = LONG_MIN;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (arr[i].first > end) {
            ans++;
            end = arr[i].second;
        }
    }

    printf("%d\n", ans);
    return 0;
}